#include "widget.h"

#include <osgQOpenGL/osgQOpenGLWidget>
#include <QBoxLayout>
#include <osgDB/ReadFile>
#include <osgViewer/Viewer>
#include <osgUtil/Optimizer>
#include <osgGA/TrackballManipulator>
#include <QLabel>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
	resize(400, 300);
	QHBoxLayout *pLayout = new QHBoxLayout(this);
	pLayout->setMargin(0);

	osgQOpenGLWidget *pOsgW = new osgQOpenGLWidget;
	pLayout->addWidget(pOsgW);
	connect(pOsgW, SIGNAL(initialized()), this, SLOT(initOsg()));
}

Widget::~Widget()
{
}

void Widget::initOsg()
{
	osgViewer::Viewer *pViewer = ((osgQOpenGLWidget *)sender())->getOsgViewer();
	pViewer->setCameraManipulator(new osgGA::TrackballManipulator());
    // D:/WorkFile/osgData/Data/boxman.osg
    // D:/WorkFile/osgData/mapdata/myMap.earth
    osg::Node *pNode = osgDB::readNodeFile("D:/pinetree.ive");
	osgUtil::Optimizer optimizer;
	optimizer.optimize(pNode);
	pViewer->setSceneData(pNode);
}
